package com.study.spring.hadoop;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;

/**
 * @author: zack
 * @date: 2020/2/7 0007 下午 10:30
 * @Description:
 */
public class TestHdfs {


    private static final String SOURCE_PATH = "D:\\software\\VMware-workstation-full-15.5.0-14665864.exe";
    private static final String DEST_PATH = "/hbase/upload/settings.jar";
    private static final String MASTER_URI = "hdfs://127.0.0.1:9000";


    public static void testUpload() throws URISyntaxException, IOException {
        Configuration conf = new Configuration();
        FileSystem fs = FileSystem.get(new URI(MASTER_URI), conf);
        InputStream in = new FileInputStream(SOURCE_PATH);
        OutputStream out = fs.create(new Path("/user/root/test-hadoop"));
        IOUtils.copyBytes(in, out, conf);
    }

    public static void main(String[] args) throws IOException, URISyntaxException {

        System.setProperty("hadoop.home.dir", "D:\\soft\\hadoop-2.7.3");
        testUpload();
    }

    public void readFile() throws Exception {
//        String uri = "hdfs://10.111.32.142:8020/user/zhaochao/20180727/sms.1532681090912.log.tmp";
//        Configuration conf = new Configuration();
//        FileSystem fs = FileSystem.get(URI.create(uri),conf);
//        try(InputStream in = fs.open(new Path(uri)))
//        {
//            IOUtils.copy(in,System.out);
//        }
    }
}
